home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-04 | 4.3 KB | 153 lines | [TEXT/MMCC] |
- //•———————————————————————————————•••———————————————————————————————•//
- //•—————————————————————— Another old C source —————————————————————•//
- //•—————————————————— "brought back from the dead" —————————————————•//
- //•——————————————————————— by Kenneth A. Long ——————————————————————•//
- //•——————————————————————— at itty bitty bytes™ ————————————————————•//
- //•————————————— Made to run on Think C™ on 13 March 1994 ——————————•//
- //•————————— Made to run on Code Warrior on 20 November 1994 ———————•//
- //•———————————————————————————————•••———————————————————————————————•//
-
- //• Written 1:17 pm Jun 12, 1986
- //• by Steve Hawley
- //• sdh@joevax.UUCP
- //• Posted on uiucdcsb:net.sources.mac
- //• "Sleep Utility"
-
- //• The following is the source to a sleep utility. It is equivalent
- //• to the blit demo bounce. It clears the *entire* screen to black
- //• thus allowing you to leave your mac on w/o having the menu bar
- //• burned in.
-
-
- #define range 12;
- #define size 32 //• Should be a power of 2.
- #define bound_X qd.screenBits.bounds.right
- #define bound_Y qd.screenBits.bounds.bottom
-
- GrafPort myPort;
-
- int x1[size], x2[size], y1[size], y2[size], dx1, dx2, dy1, dy2;
-
-
- //o Bounce - Steve Hawley 6/13/86 Written in Aztec C V 1.06H.
-
- //o This is a Mac implementation of the bounce program written for
- //o the BLIT and 5620 terminals. It simply keeps track of a list of
- //o end points of lines, erasing the oldest and replacing it with
- //o one derived from the newest plus some dx and dy values.
-
-
- int abs (int i)
- {
-
- //o Absolute value.
- if (i < 0)
- return - i;
- else
- return i;
- }
-
- WindowPtr genericWindow;
- Rect dragRect;
- Rect windowBounds;
-
- void SetUpWindow (void) //• A KAL addition.
- {
- dragRect = qd.screenBits.bounds;
-
- SetRect (&windowBounds, 0, 0, bound_X, bound_Y);
- genericWindow = NewWindow (0L, &windowBounds, "\pBullseye", true, noGrowDocProc, (WindowPtr) -1L, true, 0);
- FillRect (&windowBounds, &qd.black);
- SetPort (genericWindow);
- }
-
- init ()
- {
- int i;
-
- dx1 = Random () % range + 4; /* create random dx's and dy's */
- dx2 = Random () % range + 4;
- dy1 = Random () % range + 4;
- dy2 = Random () % range + 4;
-
- x1[0] = abs (Random () % bound_X) + 1; /* create first point */
- x2[0] = abs (Random () % bound_X) + 1;
- y1[0] = abs (Random () % bound_Y) + 1;
- y2[0] = abs (Random () % bound_Y) + 1;
-
- MoveTo (x1[0], y1[0]);
- LineTo (x2[0], y2[0]); /* draw it */
-
- for (i = 1; i < size; i++)
- { /* derive the rest of the points */
- if ((x1[i - 1] + dx1 < 0) || (x1[i - 1] + dx1 > bound_X))
- dx1 = - dx1;
- x1[i] = x1[i - 1] + dx1;
- if ((x2[i - 1] + dx2 < 0) || (x2[i - 1] + dx2 > bound_X))
- dx2 = - dx2;
- x2[i] = x2[i - 1] + dx2;
- if ((y1[i - 1] + dy1 < 0) || (y1[i - 1] + dy1 > bound_Y))
- dy1 = - dy1;
- y1[i] = y1[i - 1] + dy1;
- if ((y2[i - 1] + dy2 < 0) || (y2[i - 1] + dy2 > bound_Y))
- dy2 = - dy2;
- y2[i] = y2[i - 1] + dy2;
- MoveTo (x1[i], y1[i]); /* draw them */
- LineTo (x2[i], y2[i]);
- }
- }
-
-
- main ()
- {
- Rect myRect;
- register int i, j;
- GrafPtr savePort;
-
- InitGraf (&qd.thePort);
-
- InitWindows (); //• Added by Ken Long because blackening the
- //• whole screen (next comment) did not
- //• UNblacken!
- SetUpWindow ();
-
- OpenPort (&myPort); //o I create my own port so I don't need
- //o windows and can blacken the whole screen.
-
-
- HideCursor ();
-
- SetRect (&myRect, 0, 0, bound_X, bound_Y);
- PenPat (&qd.black);
- PaintRect (&myRect); //o Clear screen to black.
- PenMode (patXor); //o use exclusive-or drawing to ease animation.
- init ();
- i = 0; //o Oldest set of points.
-
- while (!Button ()) //o repeat until button is down.
- {
- j = i - 1; //o find newest points.
- if (j< 0) j = size - 1;
- MoveTo (x1[i], y1[i]); //o erase old.
- LineTo (x2[i], y2[i]);
- //o derive new point */
- if ((x1[j] + dx1 < 0) || (x1[j] + dx1 > bound_X))
- dx1 = - dx1;
- x1[i] = x1[j] + dx1;
- if ((x2[j] + dx2 < 0) || (x2[j] + dx2 > bound_X))
- dx2 = - dx2;
- x2[i] = x2[j] + dx2;
- if ((y1[j] + dy1 < 0) || (y1[j] + dy1 > bound_Y))
- dy1 = - dy1;
- y1[i] = y1[j] + dy1;
- if ((y2[j] + dy2 < 0) || (y2[j] + dy2 > bound_Y))
- dy2 = - dy2;
- y2[i] = y2[j] + dy2;
- MoveTo (x1[i], y1[i]); //o draw new line.
- LineTo (x2[i], y2[i]);
- i = (i + 1) & size - 1; //o get oldest line.
- }
- // SetPort (savePort);
- }
- //o End of text from uiucdcsb:net.sources.mac.
-